
<script type="text/javascript">

$(function(){	
	$("#content").css("height","750px");
	
	//busca exercicio do combo
	$("#txtTrabalho").load("actions/ajaxlistarExerciciosComboAction.php");
})

function buscaPerguntas(exercicio_id){
	
	
		$('#exercicio_id').val(exercicio_id);
		
		$.ajax({
			type:"POST",
			url:"actions/exerciciosAction.php",
			data:{acao:'buscar',
				  exercicio_id:exercicio_id,
				  id_exercicio_professor:$("#txtId").val()
			},
			dataType:"json",
			success: function(data, textStatus, request){
				
				$("#exibe").show();
				
				$("#txtPergunta").html(data['pergunta']);
				$("#resposta1").html(data['resposta_1']);
				$("#resposta2").html(data['resposta_2']);
				$("#resposta3").html(data['resposta_3']);	
				$("#resposta4").html(data['resposta_4']);
				$("#resposta5").html(data['resposta_5']);
				$("#txtId").val(data['id_exercicio_professor']);
				$("#exibe_conteudo").load("actions/exibeArquivoExerciciosAction.php?id_exercicio_professor="+data['id_exercicio_professor']);
				
				$("input[type=radio]").removeAttr('checked');
				
				if(data['resposta_x']!="" && data['resposta_x']!=null){
					
					if(data['resposta_x']==data['resposta_ok']){
						$("#certo").show();	
						$("#errado").hide();	
					}else{
						$("#errado").show();	
						$("#certo").hide();					
					}					
					
					$("input[type=radio]").attr("disabled","disabled");
					$("input:radio[value="+data['resposta_x']+"]").attr("checked","checked");
					$("#btnSalvar").hide();
					$("#mov").show();
				}
				
					
			}
		});
}

function salvaPergunta(value){
	$.ajax({
		type:"POST",
		url:"actions/exerciciosAction.php",
		data:{acao:'salvar',chk:value,id:$("#txtId").val()},
		dataType:"json",
		success: function(data, textStatus, request){	
			buscaPerguntas();
		}	
	});
}


function guardarResposta(valor){
	$("#txtResposta").val(valor);	
}

</script>

<input type="text" id="exercicio_id" name="exercicio_id" />

<div id="formularios">

<fieldset style="height:450px;width:800px;padding:10px;">

        <legend>
            <img src="../images/topoPaginas/Icon_Exercícios_Menu.png"/>
        </legend>
        <div id="btnSairForms">
        <a href="/?pg=home" title="Sair" style="border:0;">
        	<img src="images/btnOutros/btnSairForms.png"/>
        </a>
        </div>
        <br />
        <div style="padding-left:600px;"> 
        	<select id="txtTrabalho" name="txtTrabalho" onchange="buscaPerguntas(this.value)" style="width:160px;">
            	<option value="">Selecione um Exercício</option>
            </select>
        </div>
        
        <div style="padding-left:50px;"> 
        <div style="display:none;" id="exibe">
        	<form action="actions/exerciciosAction.php" method="post" id="formExercicios" name="formExercicios">
        		<input type="hidden" id="txtId" name="txtId" />
                <table width="700" border="0">
                  <tr height="45">
                    <td colspan="2"><span id="txtPergunta" style="color:#000;font-size:14px;font-weight:bold;"></span></td>
                  </tr>
                  <tr>
                    <td width="383"><input type="hidden" id="txtResposta" name="txtResposta" /></td>
                    <td width="207" rowspan="6">
                    	<div id="exibe_conteudo" style="border:1px solid #C1CDC1;width:250px;height:250px;color:#666;text-align:center;">
                        	
                        </div>                    
                    </td>
                  </tr>
                  <?php
                  
				  	//ordenando as questoes.
				  	$array = array("1", "2", "3", "4", "5");
					$rand_keys = array_rand($array,5);				
				
					for($i=0;$i<5;$i++){
						//echo $array[$rand_keys[$i]] . "\n";
						echo "<tr height='35'>                  	
								<td><input type='radio' value='".$array[$rand_keys[$i]]."' id='chk' name='chk' onclick='guardarResposta(this.value)'/>&nbsp;&nbsp;&nbsp;<span id='resposta".$array[$rand_keys[$i]]."' class='respostas'></span></td>
							  </tr>";
				  
				  
                   } 
				   ?>                  
                  <tr height="35">
                    <td>&nbsp;</td>
                    <td align="center">
                    	<span id="certo" style="display:none;"><img src="../images/btnOutros/certo.png" width="64" height="64"/></span>
                        <span id="errado" style="display:none;"><img src="../images/btnOutros/errado.png" width="64" height="64"/></span>
                    </td>
                  </tr>
                </table>
                
    </form> 
    	</div>
      </div>    
  </fieldset>
    
    <div style="text-align:center;">
    
    
    	<div style="margin-top:10px;float:left;width:700px;text-align:center;">
             <a href="javascript:void(0);" title="Salvar Alterações" id="btnSalvar"  onclick="salvaPergunta( $('#txtResposta').val() );" style="border:0;text-decoration:none;padding-left:12px;">
                <img src="images/btnOutros/btnSalvar.png" />
        	</a> 
    	</div>
        
        <div id="mov" style="margin-top:10px;display:none;float:left;">
        <a href="javascript:void(0);" onclick="buscaPerguntas( $('#exercicio_id').val() );" title="Anterior" style="border:0;text-decoration:none;">
            <img src="images/btnOutros/anterior.png" width="42" height="42"/>
        </a>
        &nbsp;&nbsp;
    	<a href="javascript:void(0);" title="Próximo" onclick="buscaPerguntas( $('#exercicio_id').val() );" style="border:0;text-decoration:none;">
            <img src="images/btnOutros/proximo.png" width="42" height="42" />
        </a>
        </div>  
       
        
    </div>
    
</div>

</div>
